package demo.ws.rest_cxf;

import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import org.apache.cxf.endpoint.Client;

import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * 客户端调用已发布REST服务
 * 2.JAX-RS 2.0 时代客户端
 */
public class JAXRS20Client {

    public static void main(String[] args){
        String baseAddress = "http://localhost:8080/ws/rest";

        JacksonJsonProvider jsonProvider = new JacksonJsonProvider();
    //  List<Product> productList=...返回带有泛型的List
        List productList = ClientBuilder.newClient()
                .register(jsonProvider)
                .target(baseAddress)
                .path("/products")
                .request(MediaType.APPLICATION_JSON)
                .get(List.class);
        //      .get(new GenericType<List<Product>>(){})
        for (Object product : productList){
            System.out.println(product);
        }
    }
}
